﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NTTHAO.Web.BL.Authentication;
using NTTHAO.DBAccess;

public partial class admin_webparts_Plug_ins_User2_UserList : System.Web.UI.UserControl
{
    public static readonly int PAGE_SIZE = 50;
    public int _PageNo = 1;
    public int _PageCount = 1;
    public long _TotalItem = 0;
    public string _PageUrl = "";

    public static int ROW_COUNT_LIMIT = 100;
    public DataTable _SearchResult = null;
    public string _Title = "";
    public int _ListType = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            _PageUrl = "?type=" + Request.QueryString["type"] + "&name=" + Request.QueryString["name"] + "&action=" + Request.QueryString["action"] + "&filter=" + Request.QueryString["filter"];
            if (Request.QueryString["page"] != null)
            {
                Int32.TryParse(Request.QueryString["page"].Trim(), out _PageNo);
            }

            string filter = Request.QueryString["filter"];

            if ("create".Equals(filter, StringComparison.OrdinalIgnoreCase))
            {
                SortParameterCollection sortColl = new SortParameterCollection();
                sortColl.Add(User.JOINDATE__COLUMN_NAME, SortType.Decrease);

                _SearchResult = User.GetPage(UserStatus.NONE, sortColl, _PageNo, PAGE_SIZE, ref _TotalItem);

                this._PageCount = (int)(this._TotalItem / PAGE_SIZE + (this._TotalItem % PAGE_SIZE != 0 ? 1 : 0));
                this._PageCount = this._PageCount < 1 ? 1 : this._PageCount;

                _Title = "Người dùng vừa tạo";
            }
            else if ("username".Equals(filter, StringComparison.OrdinalIgnoreCase))
            {
                SortParameterCollection sortColl = new SortParameterCollection();
                sortColl.Add(User.USERNAME__COLUMN_NAME, SortType.Increase);

                _SearchResult = User.GetPage(UserStatus.NONE, sortColl, _PageNo, PAGE_SIZE, ref _TotalItem);

                this._PageCount = (int)(this._TotalItem / PAGE_SIZE + (this._TotalItem % PAGE_SIZE != 0 ? 1 : 0));
                this._PageCount = this._PageCount < 1 ? 1 : this._PageCount;

                _Title = "Danh sách người dùng (sắp xếp theo tên đăng nhập)";
            }
        }
        catch { }
    }
}
